﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DevComponents.DotNetBar;
using Kxzz.Common;
using Kxzz.SettingForm;
using Kxzz.Enums;
using DevComponents.DotNetBar.Rendering;

namespace Kxzz
{
    public partial class frmSetting : DevComponents.DotNetBar.Office2007Form
    {
        #region 变量
        private IniHelper iniHelper = new IniHelper(Application.StartupPath + "//Config//config.ini");
        private SettingMode DefaultMode;
        #endregion

        #region  操作列表项
        /// <summary>
        /// 操作列表项
        /// </summary>
        public class ListBoxHandleItem
        {
            private string text;
            private SettingMode settingMode;

            public ListBoxHandleItem(string text, SettingMode settingMode)
            {
                this.text = text;
                this.settingMode = settingMode;
            }
            public string Text
            {
                get { return text; }
                set { text = value; }
            }
            public SettingMode SettingMode
            {
                get { return settingMode; }
                set { settingMode = value; }
            }
        }
        #endregion

        #region 初始化构造函数
        public frmSetting()
        {
            InitializeComponent();

            InitFormSkin();
            this.DefaultMode = SettingMode.All;
        }

        public frmSetting(SettingMode defaultType)
        {
            InitializeComponent();

            InitFormSkin();
            this.DefaultMode = defaultType;
        }

        private void frmSet_Load(object sender, EventArgs e)
        {
            FormInit();
            this.ShowHandle(SettingMode.Proxy);
        }

        private void bItem_Click(object sender, EventArgs e)
        {
            string str = sender.ToString();
            SettingMode sm = SettingMode.Proxy;

            switch (str)
            {
                case "网络设置":
                    sm = SettingMode.Proxy;
                    break;
                case "飞信设置":
                    sm = SettingMode.Fetion;
                    break;
                case "花园设置":
                    sm = SettingMode.Garden;
                    break;
                case "基本设置":
                    sm = SettingMode.Nomal;
                    break;
                default:
                    sm = SettingMode.Proxy;
                    break;
            }
            //显示操作类型

            this.ShowHandle(sm);
        }
        #endregion

        #region PrvateMethod
        /// <summary>
        /// 根据类型显示不同设置窗体
        /// </summary>
        /// <param name="settingType"></param>
        private void ShowHandle(SettingMode settingMode)
        {
            //根据类型显示不同窗体
            switch (settingMode)
            {
                case SettingMode.Proxy:
                    this.panelHandleForm.Controls.Clear();
                    this.ShowProxyForm();
                    break;
                case SettingMode.Fetion:
                    this.panelHandleForm.Controls.Clear();
                    this.ShowFetionForm();
                    break;
                case SettingMode.Garden:
                    this.panelHandleForm.Controls.Clear();
                    this.ShowGardenForm();
                    break;
                case SettingMode.Nomal:
                    this.panelHandleForm.Controls.Clear();
                    this.ShoNomalForm();
                    break;
                default:
                    this.panelHandleForm.Controls.Clear();
                    this.ShowProxyForm();
                    break;
            }
        }

        /// <summary>
        /// 窗体初始化
        /// </summary>
        private void FormInit()
        {
            //根据类型显示不同窗体
            switch (this.DefaultMode)
            {
                case SettingMode.Proxy:
                    this.RegisterHandle("网络设置", SettingMode.Proxy);
                    this.sideBarPanelItem2.Visible = false;
                    break;
                case SettingMode.All:
                    this.sideBarPanelItem2.Visible = true;
                    this.RegisterHandle("网络设置", SettingMode.Proxy);
                    this.RegisterHandle("基本设置", SettingMode.Nomal);
                    this.RegisterHandle("飞信设置", SettingMode.Fetion);
                    this.RegisterHandle("花园设置", SettingMode.Garden);
                    break;
                default:
                    this.RegisterHandle("网络设置", SettingMode.Proxy);
                    break;
            }
        }

        /// <summary>
        /// 注册事件
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        public void RegisterHandle(string text, SettingMode type)
        {
            //添加操作项
            ButtonItem bi = new ButtonItem(type.ToString(), text);
            bi.Tooltip = text;
            bi.Click += new EventHandler(this.bItem_Click);
            this.sideBarPanelItem1.SubItems.Add(bi);
        }
        /// <summary>
        /// 显示代理设置窗体
        /// </summary>
        private void ShowProxyForm()
        {
            frmProxySetting proxyForm = new frmProxySetting();
            proxyForm.BackColor = this.BackColor;
            proxyForm.FormBorderStyle = FormBorderStyle.None;
            proxyForm.TopLevel = false;
            this.panelHandleForm.Controls.Add(proxyForm);
            proxyForm.Show();
        }

        /// <summary>
        /// 显示飞信设置窗体
        /// </summary>
        private void ShowFetionForm()
        {
            frmFetionSetting fetionForm = new frmFetionSetting();
            fetionForm.BackColor = this.BackColor;
            fetionForm.FormBorderStyle = FormBorderStyle.None;
            fetionForm.TopLevel = false;
            this.panelHandleForm.Controls.Add(fetionForm);
            fetionForm.Show();
        }

        /// <summary>
        /// 花园设置
        /// </summary>
        private void ShowGardenForm()
        {
            frmGardenSetting gardenForm = new frmGardenSetting();
            gardenForm.BackColor = this.BackColor;
            gardenForm.FormBorderStyle = FormBorderStyle.None;
            gardenForm.TopLevel = false;
            this.panelHandleForm.Controls.Add(gardenForm);
            gardenForm.Show();
        }

        /// <summary>
        /// 基本设置
        /// </summary>
        private void ShoNomalForm()
        {
            frmNomalSetting nomalForm = new frmNomalSetting();
            nomalForm.BackColor = this.BackColor;
            nomalForm.FormBorderStyle = FormBorderStyle.None;
            nomalForm.TopLevel = false;
            this.panelHandleForm.Controls.Add(nomalForm);
            nomalForm.Show();
        }

        private void InitFormSkin()
        {
            if (this.iniHelper.read("Setup", "skin") != "")
            {
                eOffice2007ColorScheme colorScheme = (eOffice2007ColorScheme)Enum.Parse(typeof(eOffice2007ColorScheme), this.iniHelper.read("Setup", "skin"));
                this.Office2007ColorTable = colorScheme;
            }
        }
        #endregion
    }
}
